home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / inst / instcreate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-31  |  4.5 KB  |  185 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9. static char *copyright = "Copyright (C) 1992 The Geometry Center";
  10.  
  11. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  12.  
  13. /*
  14.  * Inst creation, editing, retrieval and deletion.
  15.  */
  16.  
  17. #include "instP.h"
  18. #include "transobj.h"
  19.  
  20. void
  21. InstDelete( inst )
  22.     Inst *inst;
  23. {
  24.     if( inst ) {
  25.     if(inst->geom) GeomDelete(inst->geom);
  26.     if(inst->geomhandle) HandlePDelete(&inst->geomhandle);
  27.     if(inst->tlist) GeomDelete(inst->tlist);
  28.     if(inst->tlisthandle) HandlePDelete(&inst->tlisthandle);
  29.     if(inst->axishandle) HandlePDelete(&inst->axishandle);
  30.     }
  31. }
  32.  
  33. Inst *
  34. InstCopy( Inst *inst ) 
  35. {
  36.   register Inst *ni;
  37.  
  38.   ni = OOGLNewE(Inst, "InstCopy: Inst");
  39.   GGeomInit(ni, inst->Class, inst->magic, NULL);
  40.   TmCopy(inst->axis, ni->axis);
  41.   ni->geom = GeomCopy(inst->geom);
  42.   ni->geomhandle = NULL;
  43.   ni->tlist = GeomCopy(inst->tlist);
  44.   ni->tlisthandle = NULL;
  45.   ni->axishandle = NULL;
  46.   ni->instflag = inst->instflag;
  47.   ni->seq = inst->seq;
  48.   return(ni);
  49.  
  50. }
  51.  
  52. Geom *
  53. InstReplace( register Inst *inst, register Geom *geom )
  54. {
  55.     register Geom *old;
  56.  
  57.     if(inst == NULL)
  58.     return NULL;
  59.  
  60.     old = inst->geom;
  61.     inst->geom = geom;
  62.     return old;
  63. }
  64.  
  65. int
  66. InstGet( register Inst *inst, int attr, register void *attrp )
  67. {
  68.     switch(attr) {
  69.     case CR_GEOM: *(Geom **)attrp = inst->geom; break;
  70.     case CR_GEOMHANDLE: *(Handle **)attrp = inst->geomhandle; break;
  71.     case CR_TLIST: *(Geom **)attrp = inst->tlist; break;
  72.     case CR_TLISTHANDLE: *(Geom **)attrp = (Geom *)inst->tlisthandle; break;
  73.     case CR_AXISHANDLE: *(Handle **)attrp = inst->axishandle; break;
  74.     case CR_AXIS:
  75.     TmCopy(inst->axis, (float (*)[4])attrp);
  76.     return (inst->tlist == NULL && inst->tlisthandle == NULL) ? 1 : 0;
  77.     default:
  78.     return -1;
  79.     }
  80.     return 1;
  81. }
  82.  
  83. Inst *
  84. InstCreate ( Inst *exist, GeomClass *classp, va_list a_list )
  85. {
  86.     register Inst *inst;
  87.     int attr;
  88.     int fourd = 0;
  89.     int copy = 1;
  90.     float *f;
  91.     Transform *t;
  92.     Geom *g;
  93.     Handle *h;
  94.  
  95.     if (exist == NULL) {
  96.     inst = OOGLNewE(Inst, "InstCreate inst");
  97.     GGeomInit (inst, classp, INSTMAGIC, NULL);
  98.     TmIdentity(inst->axis);
  99.     inst->instflag = 0;
  100.     inst->geomhandle = NULL;
  101.     inst->geom = NULL;
  102.     inst->tlisthandle = NULL;
  103.     inst->tlist = NULL;
  104.     inst->axishandle = NULL;
  105.     } else {
  106.     /* Check that exist is an inst. */
  107.     inst = exist;
  108.     }
  109.  
  110.     while (attr = va_arg (a_list, int)) {
  111.     switch(attr) {
  112.     case CR_FLAG:
  113.         inst->instflag = va_arg(a_list, int);
  114.         break;
  115.  
  116.     case CR_GEOMHANDLE:
  117.         h = va_arg(a_list, Handle *);
  118.         if(copy) RefIncr((Ref *)h);
  119.         if(inst->geomhandle)
  120.         HandlePDelete(&inst->geomhandle);
  121.         inst->geomhandle = h;
  122.         HandleRegister(&inst->geomhandle, (Ref *)inst, &inst->geom, HandleUpdRef);
  123.         break;
  124.  
  125.     case CR_HANDLE_GEOM:
  126.         h = va_arg(a_list, Handle *);
  127.         if(copy) RefIncr((Ref*)h);
  128.         if(inst->geomhandle)
  129.         HandlePDelete(&inst->geomhandle);
  130.         inst->geomhandle = h;
  131.         if(h) HandleRegister(&inst->geomhandle,
  132.             (Ref *)inst, &inst->geom, HandleUpdRef);
  133.         /* Fall into CR_GEOM case */
  134.  
  135.     case CR_GEOM:
  136.         g = va_arg(a_list, Geom *);
  137.         if(copy) RefIncr((Ref *)g);
  138.         if(inst->geom)
  139.         GeomDelete(inst->geom);
  140.         inst->geom = g;
  141.         break;
  142.  
  143.     case CR_AXIS:
  144.         t = va_arg(a_list, Transform *);
  145.         InstTransformTo(inst, (*t));
  146.         break;
  147.  
  148.     case CR_AXISHANDLE:
  149.         h = va_arg(a_list, Handle *);
  150.         if(copy) RefIncr((Ref *)h);
  151.         if(inst->axishandle)
  152.         HandlePDelete(&inst->axishandle);
  153.         inst->axishandle = h;
  154.         HandleRegister(&inst->axishandle, (Ref *)inst, inst->axis, TransUpdate);
  155.         break;
  156.  
  157.     case CR_TLIST:
  158.         g = va_arg (a_list, Geom *);
  159.         if(copy) RefIncr((Ref *)g);
  160.         if(inst->tlist)
  161.         GeomDelete(inst->tlist);
  162.         inst->tlist = g;
  163.         break;
  164.  
  165.     case CR_TLISTHANDLE:
  166.         h = va_arg(a_list, Handle *);
  167.         if(copy) RefIncr((Ref *)h);
  168.         if(inst->tlisthandle != NULL)
  169.         HandlePDelete(&inst->tlisthandle);
  170.         inst->tlisthandle = h;
  171.         HandleRegister(&inst->tlisthandle, (Ref *)inst, &inst->tlist, HandleUpdRef);
  172.         break;
  173.  
  174.     default:
  175.         if(GeomDecorate(inst, ©, attr, &a_list)) {
  176.         OOGLError (0, "InstCreate: Undefined option: %d", attr);
  177.         if(exist == NULL) GeomDelete ((Geom *)inst);
  178.         return NULL;
  179.         }
  180.     }
  181.     }
  182.  
  183.     return inst;
  184. }
  185.